cmake_minimum_required(VERSION 3.10)
project(myapp LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(GitVersion)          # 拿到 APP_VERSION

# 1) 让源码能用 APP_VERSION
configure_file(
  "${CMAKE_SOURCE_DIR}/src/version.h.in"
  "${CMAKE_BINARY_DIR}/generated/version.h"
  @ONLY
)

# 2) 把版本写进 ELF .note 段（可选）
set(CMAKE_EXE_LINKER_FLAGS
    "${CMAKE_EXE_LINKER_FLAGS} -Wl,--defsym,__note_version=0")

# 3) 编译可执行文件
add_executable(myapp src/main.cpp)
target_include_directories(myapp PRIVATE "${CMAKE_BINARY_DIR}/generated")
target_compile_definitions(myapp PRIVATE APP_VERSION=\"${APP_VERSION}\")